package com.cyy.cn.controller;

import java.util.Map;

import com.cyy.cn.pojo.Article;
import com.cyy.cn.service.ArticleSearchService;
import entity.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import entity.Result;
import entity.StatusCode;
/**
 * enterprise控制器层
 * @author Administrator
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/enterprise")
public class ArticleSearchController {

	@Autowired
	private ArticleSearchService articleSearchService;
	



	/**
	 * 增加
	 * @param article
	 */
	@RequestMapping(method=RequestMethod.POST)
	public Result add(@RequestBody Article article  ){
		articleSearchService.add(article);
		return new Result(true,StatusCode.OK,"增加成功");
	}

	@RequestMapping(value="/search/{keywords}/{page}/{size}",method= RequestMethod.GET)
	public Result findByTitleLike(@PathVariable String keywords, @PathVariable int page, @PathVariable int size){
		Page<Article> articlePage = articleSearchService.findByTitleLike(keywords,page,size);
		return new Result(true, StatusCode.OK, "查询成功", new PageResult<Article>(articlePage.getTotalElements(), articlePage.getContent()));
	}
}
